﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Model
{
    public class ActivityFeedbackRepository
    {
        private JzSportDbContext _dbContext;

        public ActivityFeedbackRepository(JzSportDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public void Create(ActivityFeedback activityFeedback)
        {
            _dbContext.Set<ActivityFeedback>().Add(activityFeedback);
        }

        public List<Data.ActivityFeedbackView> Get(Guid activityId)
        {
            return _dbContext.Set<ActivityFeedback>().Where(p => p.ActivityId == activityId)
                .Join(_dbContext.Set<Account>(),
                    l=>l.CreatorId,
                    r=>r.Id,
                    (l,r)=> new Data.ActivityFeedbackView(){
                        Id = l.Id,
                        ActivityId = l.ActivityId,
                        Content = l.Content,
                        CreatedTime = l.CreatedTime,
                        CreatorId = l.CreatorId,
                        CreatorAvatarUrl = r.AvatarUrl,
                        CreatorNickName = r.NickName
                    })
                .OrderBy(p => p.CreatedTime)
                .ToList();
        }
    }
}
